package com.example.cvte.config;

import com.example.cvte.util.ConstVariable;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * @author 郝文雪
 * @date 2022/10/31 23:51
 * @Description 用户登录拦截
 */
@Component
public class UserLoginIntercept implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        HttpSession session=request.getSession(false);
        if(session!=null&&session.getAttribute(ConstVariable.USER_SESSION_KEY)!=null){
            return true;
        }
        return false;
    }
}